from django.http import HttpResponse, JsonResponse
from django.views.decorators.http import require_http_methods
import base64, json
from .confs.conf import get_mirror_conn
from django.views.decorators.csrf import csrf_exempt
from datetime import datetime

def_response_o = {
    "code": 0,
    "result": "",
    "message": "",
    "type": 'success',
  }


def get_data(param):
    result=""
    if param:
        result = {
            'site': param["site"] if param["site"] else '',
            'email': param["email"] if param["email"] else '',
            'order_id': param["orderId"] if param["orderId"] else '',
            'create_time':datetime.now(),
            "is_send":1
        }
    return result

@require_http_methods(["POST"])
@csrf_exempt
def save_need_send_email(request):
    print("哈哈哈哈")
    global insert
    params = json.loads(request.body)
    print(params)
    data=get_data(params)
    db_conn = get_mirror_conn()
    if data:
        db_conn.insert('dlz_send_emai_list', data)
    re = json.loads(json.dumps(def_response_o,ensure_ascii=False))
    return JsonResponse(re)